
#include "strip_all.h"
#include "find_all.h"




std::vector<std::string> strip_all( std::string line, std::string match, bool keepEmpty ){

  std::vector<std::string> result;
  result.clear();

  // empty line
  if ( line.empty() )
    return result;

  // empty match
  if ( match.empty() )
    return result;

  std::vector<size_t> positions = find_all( line, match );
  // positions now stores the absolute positions of the matches

  std::string temp;
  size_t start = 0;
  size_t index = 0;

  while( index < positions.size() ) {

    temp =  line.substr( start, positions[index]-start ); 

    // store empty results? this may be useful sometimes
    if ( keepEmpty || (!keepEmpty && temp.size()!=0) )
      result.push_back(temp );

    start=positions[index] + match.size();
    index++;

    // if this is the end of the line and there is still a substring to extract
    if ( index == positions.size() ) {
      temp = line.substr( start, line.size()-start);

      if ( keepEmpty || (!keepEmpty && temp.size()!=0) )
        result.push_back(temp );
    }

  }  // loop on positions to fill the result vector


  return result;
}


